angular.module(moduleName + '.directives')
  .directive('hrIonPopup', function($ionicPopup) {
    return {
      restrict: 'EA',
      templateUrl: 'hr-ion-popup/hr-ion-popup.html',
      replace: true,
      transclude: true,
      scope: {
        type: '@',
        showText: '@',
        showTeml: '@',
        showTitle: '@',
        showSubTitle: '@'
      },
      link: function(scope) {
        scope.isShow = false;
        scope.isConfirm = false;
        scope.isAlert = false;
        if (scope.type == "show") {
          scope.isShow = true
        } else if (scope.type == "confirm") {
          scope.isConfirm = true
        } else if (scope.type == "alert") {
          scope.isAlert = true
        }
        scope.showPopup = function() {
          scope.data = {}
          var myPopup = $ionicPopup.show({
            template: '<input type="password" ng-model="data.wifi">',
            title: 'Enter Wi-Fi Password',
            subTitle: 'Please use normal things',
            scope: scope,
            buttons: [{
              text: 'Cancel'
            }, {
              text: '<b>Save</b>',
              type: 'button-positive',
              onTap: function(e) {
                if (!scope.data.wifi) {
                  //不允许用户关闭，除非他键入wifi密码
                  e.preventDefault()
                } else {
                  return scope.data.wifi
                }
              }
            }]
          });

          // 一个确认对话框
          scope.showConfirm = function() {
            var confirmPopup = $ionicPopup.confirm({
              title: 'Consume Ice Cream',
              template: 'Are you sure you want to eat this ice cream?'
            });
          };

          // 一个提示对话框
          scope.showAlert = function() {
            var alertPopup = $ionicPopup.alert({
              title: 'Don\'t eat that!',
              template: 'It might taste good'
            });
          };
        }
      }
    }
  });
